<template>
  <div class="order_container">
    <el-card class="box-card">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>商品管理</el-breadcrumb-item>
        <el-breadcrumb-item>添加商品</el-breadcrumb-item>
      </el-breadcrumb>

      <el-row class="search">
        <el-col :span="8">
          <el-input placeholder="请输入内容"
                    clearable>
            <el-button slot="append"
                       icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="orderlist"
                border
                stripe>
        <el-table-column type="index">
        </el-table-column>
        <el-table-column prop="order_number"
                         label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price"
                         label="订单价格">
        </el-table-column>
        <el-table-column prop="pay_status"
                         label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success"
                    v-if="scope.row.pay_status === '1'">
              已付款
            </el-tag>
            <el-tag type="danger"
                    v-else>
              未付款
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="path"
                         label="是否发货">
          <template slot-scope="scope">
            <template>
              {{scope.row.is_send}}
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="path"
                         label="下单时间">
          <template slot-scope="scope">
            {{scope.row.create_time |  dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作"
                         width="250px"
                         prop="level">
          <template slot-scope="scope">
            <el-button size="mini"
                       type="primary"
                       icon="el-icon-edit"
                       @click="showDialog"></el-button>
            <el-button size="mini"
                       type="success"
                       icon="el-icon-location"
                       @click="showProgressDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagesize"
                     :page-sizes="[1, 2, 5, 10]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>

      <el-dialog title="添加用户"
                 :visible.sync="showAddDialog"
                 width="30%"
                 @close="removeRess">
        <el-form label-width="100px"
                 :model="addRessForm"
                 :rules="addRessFormRules"
                 ref="addRessFormRef"
                 class="demo-ruleForm">
          <el-form-item label="省市县/区"
                        prop="addRess1">
            <el-cascader :options="cityData"
                         expand-trigger="hover"
                         v-model="addRessForm.addRess1"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址"
                        prop="addRess2">
            <el-input v-model="addRessForm.addRess2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="showAddDialog = false">取 消</el-button>
          <el-button type="primary"
                     @click="showAddDialog = false">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog title="物流进度信息"
                 :visible.sync="progressDialog"
                 width="30%">
        <el-timeline>
          <el-timeline-item v-for="(activity, index) in progressInfo"
                            :key="index"
                            :timestamp="activity.time"
                            :color="timeLIneColor">
            {{activity.context}}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="progressDialog = false">取 消</el-button>
          <el-button type="primary"
                     @click="progressDialog = false">确 定</el-button>
        </span>
      </el-dialog>

    </el-card>
  </div>
</template>

<script>
import cityData from './cityData.js'
import kuaidiData from './kuaidi.json'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      orderlist: [],
      total: 0,
      showAddDialog: false,
      addRessForm: {
        addRess1: '',
        addRess2: ''
      },
      addRessFormRules: {
        addRess1: [
          { required: true, message: '请选择省市县区', trigger: 'blur' }
        ],
        addRess2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      progressInfo: [],
      progressDialog: false,
      timeLIneColor: '#67C23A'
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单数据数据失败！')
      }
      this.orderlist = res.data.goods
      // console.log(this.orderlist)
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    removeRess () {
      this.$refs.addRessFormRef.resetFields()
    },
    showDialog () {
      this.showAddDialog = true
    },
    async showProgressDialog () {
      this.progressDialog = true
      this.$message.success('物流数据获取成功！')
      this.progressInfo = kuaidiData.data
      console.log(this.progressInfo)
    }
  }
}
</script>

<style lang="less" scoped>
.order_container {
  width: 85%;
  .search {
    margin: 15px 0;
  }
  .el-pagination {
    margin-top: 15px;
  }
}
</style>
